<?php
/*
 * @Author: lokei
 * @Date: 2023-05-20 23:32:25
 * @LastEditors: lokei
 * @LastEditTime: 2023-05-21 08:18:48
 * @Description: 
 */
namespace App\Http\Controllers\Store\Credit;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Store\StoreModel;
use Illuminate\Http\Request;

class CertificateController extends Controller {
    public function set(Request $request) {
        $store = StoreModel::where('uid', '=', $request->input('uid'))->first();
        if(!is_null($store)) {
            $store->credit_certificated = '1';
            $store->credit_level_id = $request->input('level_id');
            $store->save();
            return ResultTool::success();
        } else {
            $res = ResultTool::fail();
            $res['errorMsg'] = '商家门店不存在';
            return $res;
        }
    }

    public function cancel(Request $request) {
        $store = StoreModel::where('uid', '=', $request->input('uid'))->first();
        if(!is_null($store)) {
            $store->credit_certificated = '0';
            $store->credit_level_id = null;
            $store->save();
            return ResultTool::success();
        } else {
            $res = ResultTool::fail();
            $res['errorMsg'] = '商家门店不存在';
            return $res;
        }
    }
}